package demoredis;

import org.junit.Test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisDemo {
	
	@Test
	public void testJedis() {
		Jedis jedis = new Jedis("127.0.0.1", 6379);
		jedis.auth("cyw1024");
		
		String pingResult = jedis.ping();
		System.out.println("ping的结果:"+pingResult);
		
		String setResult = jedis.set("name","ls");
		System.out.println("setResult:"+setResult);
		
		String getResult = jedis.get("name");
		System.out.println("getResult:"+getResult);
		//释放资源
		jedis.close();
	}
	@Test
	public void testJedisPool() {
		//配置连接池
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(200);//最大连接数
		config.setMaxIdle(10);//最大空闲数
		//配置，ip地址，端口号，连接超时时间，密码
		JedisPool jedisPool = new JedisPool(config, "127.0.0.1", 6379, 10000, "cyw1024");
		//拿连接
		Jedis jedis = jedisPool.getResource();
		
		String pingResult = jedis.ping();
		
		System.out.println("ping的结果:"+pingResult);
		
		jedis.close();
		
		jedisPool.close();
	}
}
